package com.example.zhongshuishi.utils;


import com.google.gson.Gson;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * @author 鑳℃垬纾�
 * @version 1.0
 * @description TODO
 * @date 2025/5/15 16:26
 */
public class KSXPostUtil {
 public static String sendPost(String url, Map<String, Object> params) {
  try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
   HttpPost httpPost = new HttpPost(url);
   httpPost.addHeader("Content-Type", "application/json");
   // 构造JSON请求体
   String jsonBody = new Gson().toJson(params);
   httpPost.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8));

   // 执行请求
   try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
    return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
   }
  } catch (Exception e) {
   e.printStackTrace();
   return null;
  }
 }
}